import moment from 'moment';
import 'moment/locale/zh-cn';
moment.locale('zh-cn');

Template.registerHelper('momentLL', function(dateTime) {
  return moment(dateTime).format('LL');
});

Template.registerHelper('momentCalendar', function(dateTime) {
  return moment(dateTime).calendar();
});

Template.registerHelper('chatMoment', function(dateTime) {
  let a = moment(moment().format());
  let b = moment(moment(dateTime).format());
  let range = a.diff(b, 'days');

  if (range === 0) {
    return moment(dateTime).format('LT');
  }

  if (range === 1) {
    return moment(dateTime).subtract(0, 'days').calendar();
  }

  if (range > 1 && range <= 7) {
    return moment(dateTime).format('dddd h:mm');
  }

  if (range > 7) {
    return moment(dateTime).format('lll');
  }
  
  return moment(dateTime).format('lll');
});